import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author 挚爱之夕
 * @date 2021/9/12 - 09 - 12 - 19:50
 * @Description: PACKAGE_NAME
 * @Version: 1.0
 */
public class MainFrame {
    //创建歌单对象
    MusicList musicList;

    //构造器
    public MainFrame() throws IOException{
        musicList = new MusicList();
        initFrame();
    }

    //初始化界面
    public void initFrame() throws IOException,IllegalArgumentException  {
        System.out.println("====================欢迎使用歌曲管理系统=====================");
        System.out.println();
        String name;
        String author;
        double time;
        //while循环系统一直可以操作，直到输入0
        while (true) {
            System.out.print("1:查看歌单" + "\t");
            System.out.print("2:添加歌曲" + "\t");
            System.out.print("3:查询歌曲" + "\t");
            System.out.print("4:删除歌曲" + "\t");
            System.out.print("5:统计歌单中歌曲总数" + "\t");
            System.out.println("0:退出");
            System.out.println();
            System.out.println("请选择你要执行的操作：");
            //创建io流
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            int elect = Integer.parseInt(bufferedReader.readLine());
            switch (elect) {
                case 1:
                    //调用查看歌单方法
                    System.out.println("=========================查看歌单==========================");
                    musicList.printMusicSet();
                    System.out.println("==========================================================");
                    break;
                case 2:
                    //调用添加歌曲方法
                    System.out.println("==========================添加歌曲==========================");
                    System.out.println("输入歌曲名：");
                    name = bufferedReader.readLine();
                    System.out.println("请输入歌手名：");
                    author = bufferedReader.readLine();
                    System.out.println("请输入歌曲时长：");
                    time = Double.parseDouble(bufferedReader.readLine());
                    Music newMusic = new Music(name,author,time);
                    musicList.addMusic(newMusic);
                    System.out.println("添加完成：");
                    System.out.println(newMusic);
                    System.out.println("==========================================================");
                    break;
                case 3:
                    //调用查询歌曲方法
                    System.out.println("==========================查找歌曲==========================");
                    System.out.println("请输入要查找的歌曲名：");
                    name = bufferedReader.readLine();
                    Music find = musicList.findMusic(name);
                    System.out.println("找到歌曲：");
                    System.out.println(find);
                    System.out.println("==========================================================");
                    break;
                case 4:
                    //调用删除歌曲方法
                    System.out.println("==========================删除歌曲==========================");
                    System.out.println("输入要删除的歌曲名称");
                    name = bufferedReader.readLine();
                    Music delete = musicList.deleteMusic(name);
                    System.out.println("找到歌曲：");
                    System.out.println(delete);
                    System.out.println("已删除！");
                    System.out.println("==========================================================");
                    break;
                case 5:
                    System.out.println("==========================统计歌曲总数==========================");
                    int sum = musicList.total();
                    System.out.printf("歌单中%d共有首歌曲。",sum);
                    System.out.println();
                    System.out.println("==========================================================");
                    break;
                case 0:
                    System.out.println("==========================欢迎下次使用,再见！==========================");
                    return;
                default:
                    System.out.println("输入选择命令有误，重新选择！");
                    System.out.println("==========================================================");
                    break;
            }
        }
    }
}
